<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./Promise.js"></script>
</head>
<body>
    <h1>05-优化异步状态改变的then方法返回值</h1>

    <script>
         
        // 实例化一个自定义的Promise对象
        const p = new Promise((resolve, reject) => {
            setTimeout(()=>{
                //resolve("ok"); //成功
                reject("error"); //失败
            },2000);
           
        });

        // promise对象调用then方法后会继续返回一个新的promise对象
        const res = p.then(v => {
            console.log("成功", v);
            return 100;
            //return new Promise((resolve, reject) => { resolve("yes") });
            //console.log(m);
        }, r => {
            console.log("失败", r);
            console.log(m);
        });

        console.log(res); // 输出新返回的Promise对象

        

    </script>
</body>
</html>